package caiziyou.com.designpattern.singleton.type8;


/**
 * 
 * 枚举
 * 不仅能避免多线程的问题，还能避免反序列化创建对象
 * @author Administrator
 *
 */
public class SingletonTest08 {
	public static void main(String[] args) {
		Singleton instance1 = Singleton.INSTANCE;
		Singleton instance2 = Singleton.INSTANCE;
		System.out.println(instance1 == instance2);
		System.out.println("instance1.hashCode"+instance1);
		System.out.println("instance2.hashCode"+instance2);
		instance1.sayOK();
		instance2.sayOK();
	}

}

enum Singleton {

	INSTANCE;
	public void sayOK() {
		System.out.println("say ok~");
	}

}
